package com.ruoyi.web.controller.news.api;

import com.github.pagehelper.PageInfo;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.system.domain.news.NewsStandardSystem;
import com.ruoyi.system.domain.news.query.NewsStandardSystemQuery;
import com.ruoyi.system.domain.news.vo.NewsStandardSystemVo;
import com.ruoyi.system.service.news.NewsStandardSystemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/api/news/newsStandardSystem")
@Api(value = "newsStandardSystemApiController", tags  = "标准编制Api")
public class NewsStandardSystemApiController extends BaseController {

	@Resource
	private NewsStandardSystemService newsStandardSystemService;

	@ApiOperation(value = "获取单个标准编制信息", notes = "获取单个标准编制信息")
	@GetMapping("/getById")
	public R<NewsStandardSystem> getById(@RequestParam(value = "id") Long id) {
		NewsStandardSystemQuery newsStandardSystemQuery = new NewsStandardSystemQuery();
		newsStandardSystemQuery.setId(id);
		List<NewsStandardSystemVo> newsStandardSystemList = newsStandardSystemService.getNewsStandardSystemList(newsStandardSystemQuery);
		if (newsStandardSystemList!=null&&newsStandardSystemList.size()>0) {
			return R.ok(newsStandardSystemList.get(0));
		} else {
			return R.fail("数据不存在");
		}
	}

	@ApiOperation(value = "获取标准编制信息列表")
	@PostMapping(value = "/list")
	public R<PageInfo<NewsStandardSystemVo>> list(@RequestBody NewsStandardSystemQuery newsStandardSystemQuery) {
        newsStandardSystemQuery.setIsEnable("1");
		List<NewsStandardSystemVo> newsStandardSystemList = newsStandardSystemService.getNewsStandardSystemList(newsStandardSystemQuery);
		return R.ok(new PageInfo<>(newsStandardSystemList));
	}
}
